package dyy.zc.campuspay.views;

import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import dyy.zc.campuspay.R;
import dyy.zc.campuspay.bean.Pickers;
import dyy.zc.campuspay.utils.Utils;


/**
 *
 * Created by zhouchuan on 2017/3/15.
 */

public class Popwindows extends PopupWindow {
    private Context mContext;

    public View view;
    private TextView cancel,ok;
    public PickerScrollView year_picker,month_picker;
    private void findViewsByIds(View view) {
        ok = Utils.findViewsById(view,R.id.tv_ok);
        cancel = Utils.findViewsById(view,R.id.tv_cancle);
        year_picker = Utils.findViewsById(view,R.id.pickers1);
        month_picker = Utils.findViewsById(view,R.id.pickers2);
    }
    public Popwindows(Context mContext, View.OnClickListener onClickListener,
                      PickerScrollView.onSelectListener yearListener,PickerScrollView.onSelectListener monthListener)  {
        this.mContext = mContext;
        this.view = LayoutInflater.from(mContext).inflate(R.layout.pop_windows, null);

        findViewsByIds(view);
        initData();
        bind(onClickListener,yearListener,monthListener);
        /* 设置弹出窗口特征 */
        // 设置视图
        this.setContentView(this.view);
        // 设置弹出窗体的宽和高
        this.setHeight(RelativeLayout.LayoutParams.WRAP_CONTENT);
        this.setWidth(RelativeLayout.LayoutParams.MATCH_PARENT);
        // 设置弹出窗体可点击
        this.setFocusable(true);
        this.setOutsideTouchable(false);
        // 实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0xb0000000);
        // 设置弹出窗体的背景
        this.setBackgroundDrawable(dw);

        // 设置弹出窗体显示时的动画，从底部向上弹出
        this.setAnimationStyle(R.style.ActionSheetDialogAnimation);

    }

    private void initData() {
        List<Pickers> year = new ArrayList<>();
        List<Pickers> month = new ArrayList<>();
        for (int i = 0;i < 48;i++){
            String j = i + 1970 + "";
            Pickers pickers = new Pickers();
            pickers.setShowId(i + "");
            pickers.setShowConetnt(j);
            year.add(pickers);
        }
        for (int i = 0;i < 12;i++){
            String j = i + 1 + "";
            Pickers pickers = new Pickers();
            pickers.setShowId(i + "");
            pickers.setShowConetnt(j);
            month.add(pickers);
        }
        year_picker.setData(year);
        year_picker.setSelected(0);
        month_picker.setData(month);
        month_picker.setSelected(0);
    }

    private void bind(View.OnClickListener onClickListener, PickerScrollView.onSelectListener yearListener, PickerScrollView.onSelectListener monthListener) {
        ok.setOnClickListener(onClickListener);
        year_picker.setOnSelectListener(yearListener);
        month_picker.setOnSelectListener(monthListener);
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
    }
}
